package com.study.service;

import com.study.dao.UserRepository;
import com.study.domin.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author csc
 * @Description: 用于业务层
 * @date 2023/7/249:01
 */
@Service
public class UserService {



    @Autowired
    private UserRepository userRepository;

    public SysUser saveUser(SysUser user) {
        return userRepository.save(user);
    }

    public void deleteUser(Long userId) {
        userRepository.deleteById(userId);
    }

    public SysUser updateUser(SysUser user) {
        return userRepository.save(user);
    }

    public SysUser getUserById(Long userId) {
        return userRepository.findById(userId).orElse(null);
    }

    public Page<SysUser> getUsersByPage(int page, int size) {
        PageRequest pageable = PageRequest.of(page, size);
        return userRepository.findAll(pageable);
    }


    public SysUser queryByUsername(String username) {
        return userRepository.queryByUsername(username);
    }
    public SysUser queryByEmail(String email) {
        return userRepository.queryByEmail(email);
    }

}
